package com.fh.controller.building.contract;

import com.fh.controller.base.BaseController;
import com.fh.entity.Page;
import com.fh.entity.system.User;
import com.fh.service.attachment.AttachmentService;
import com.fh.service.building.RecordService;
import com.fh.service.building.contract.ContractService;
import com.fh.service.building.contract.LoanService;
import com.fh.service.building.customer.CustomerService;
import com.fh.service.building.message.SysMessageService;
import com.fh.service.hydropower.HydropowerService;
import com.fh.service.role.ShsRoleService;
import com.fh.service.system.user.UserService;
import com.fh.util.*;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.fh.controller.system.tools.GetDatalayui.getLData;
import static com.fh.controller.system.tools.GetDatalayui.getPData;


@Controller
@RequestMapping(value = "/LoanQTController")
public class LoanQTController extends BaseController {

    @Resource(name = "loanService")
    private LoanService loanService;


    @Resource(name = "sysMessageService")
    private SysMessageService sysMessageService;
    @Resource(name = "shsRoleService")
    private ShsRoleService roleService;
    @Resource(name = "userService")
    private UserService userService;

    @Resource
    private PlatformTransactionManager transactionManager;


    /****************************** 合同 ****************************************/




    /**
     * 股东list
     *
     */
    @RequestMapping(value = "/shareholderList")
    @ResponseBody
    public Object shareholderList(Page page) throws Exception {
        PageData pd = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList;
        String datalayui = null;


        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);
        try {
            pd = this.getPageData();
           // pd.put("USER_ID", user.getUSER_ID());
            page.setPd(pd);
            varList = loanService.shareholderList(page);
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }



    /**
     * 银行list
     *
     */
    @RequestMapping(value = "/bankList")
    @ResponseBody
    public Object bankList(Page page) throws Exception {
        PageData pd = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList;
        String datalayui = null;


        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);
        try {
            pd = this.getPageData();
            // pd.put("USER_ID", user.getUSER_ID());
            page.setPd(pd);
            varList = loanService.bankList(page);
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }



    /**
     * 个人情况list
     *
     */
    @RequestMapping(value = "/personnelSituationList")
    @ResponseBody
    public Object personnelSituationList(Page page) throws Exception {
        PageData pd = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList;
        String datalayui = null;


        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);
        try {
            pd = this.getPageData();
            // pd.put("USER_ID", user.getUSER_ID());
            page.setPd(pd);
            varList = loanService.personnelSituationList(page);
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }



    /**
     * 个人信息list
     *
     */
    @RequestMapping(value = "/personnelInfoList")
    @ResponseBody
    public Object personnelInfoList(Page page) throws Exception {
        PageData pd = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList;
        String datalayui = null;


        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);
        try {
            pd = this.getPageData();
            // pd.put("USER_ID", user.getUSER_ID());
            page.setPd(pd);
            varList = loanService.personnelInfoList(page);
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }


    /**
     * 资产信息  不动产list
     *
     */
    @RequestMapping(value = "/realEstateInfoList")
    @ResponseBody
    public Object realEstateInfoList(Page page) throws Exception {
        PageData pd = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList;
        String datalayui = null;


        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);
        try {
            pd = this.getPageData();
            // pd.put("USER_ID", user.getUSER_ID());
            page.setPd(pd);
            varList = loanService.realEstateInfoList(page);
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }

    /**
     * 查询资产信息  不动产
     */
    @RequestMapping(value = "/findByIdRealEstateInfo")
    @ResponseBody
    public PageData findByIdRealEstateInfo( ) {

        PageData pd = this.getPageData();
        PageData res =new PageData();
        try {

            PageData  data=   loanService.findByIdRealEstateInfo(pd);
            res.put("data", data);
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }
    /**
     * 删除资产信息  不动产
     */
    @RequestMapping(value = "/realEstateInfo_del")
    @ResponseBody
    public Object realEstateInfo_del( ) {

        PageData pd = this.getPageData();
        PageData res =new PageData();
        try {
            pd.put("IS_DEL",1);
            loanService.realEstateInfo_del(pd);
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }



    /**
     * 资产信息  动产list
     *
     */
    @RequestMapping(value = "/movableInfoList")
    @ResponseBody
    public Object movableInfoList(Page page) throws Exception {
        PageData pd = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList;
        String datalayui = null;


        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);
        try {
            pd = this.getPageData();
            // pd.put("USER_ID", user.getUSER_ID());
            page.setPd(pd);
            varList = loanService.movableInfoList(page);
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }


    /**
     * 查询资产信息  动产
     */
    @RequestMapping(value = "/findByIdMovableInfo")
    @ResponseBody
    public PageData findByIdMovableInfo( ) {

        PageData pd = this.getPageData();
        PageData res =new PageData();
        try {

            PageData  data=   loanService.findByIdMovableInfo(pd);
            res.put("data", data);
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }

    /**
     * 删除资产信息  动产
     */
    @RequestMapping(value = "/movableInfo_del")
    @ResponseBody
    public Object movableInfo_del( ) {

        PageData pd = this.getPageData();
        PageData res =new PageData();
        try {
            pd.put("IS_DEL",1);
            loanService.movableinfo_del(pd);
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }



    /**
     * 抵押物不动产信息list
     *
     */
    @RequestMapping(value = "/collateralInfoList")
    @ResponseBody
    public Object collateralInfoList(Page page) throws Exception {
        PageData pd = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList;
        String datalayui = null;


        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);
        try {
            pd = this.getPageData();
            // pd.put("USER_ID", user.getUSER_ID());
            page.setPd(pd);
            varList = loanService.collateralInfoList(page);
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }

    /**
     * 抵押物动产信息list
     *
     */
    @RequestMapping(value = "/collateralMovablesInfoList")
    @ResponseBody
    public Object collateralMovablesInfoList(Page page) throws Exception {
        PageData pd = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList;
        String datalayui = null;


        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);
        try {
            pd = this.getPageData();
            // pd.put("USER_ID", user.getUSER_ID());
            page.setPd(pd);
            varList = loanService.collateralMovablesInfoList(page);
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return datalayui;
    }
    /**
     * 查询抵押物动产信息
     */
    @RequestMapping(value = "/findByIdMovableCollateralInfo")
    @ResponseBody
    public PageData findByIdMovableCollateralInfo( ) {

        PageData pd = this.getPageData();
        PageData res =new PageData();
        try {

            PageData  data=   loanService.findByIdMovableCollateralInfo(pd);
            res.put("data", data);
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }
    /**
     * 删除抵押物  动产信息
     */
    @RequestMapping(value = "/collateralMovablesInfo_del")
    @ResponseBody
    public Object collateralMovablesInfo_del( ) {

        PageData pd = this.getPageData();
        PageData res =new PageData();
        try {
            pd.put("IS_DEL",1);
            loanService.movableCollateralInfo_del(pd);
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }
    /**
     * 查询抵押物信息
     */
    @RequestMapping(value = "/findByIdCollateralInfo")
    @ResponseBody
    public PageData findByIdCollateralInfo( ) {

        PageData pd = this.getPageData();
        PageData res =new PageData();
        try {

            PageData  data=   loanService.findByIdCollateralInfo(pd);
            res.put("data", data);
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }

    /**
     * 删除抵押物
     */
    @RequestMapping(value = "/collateralInfo_del")
    @ResponseBody
    public Object collateralinfo_del( ) {

        PageData pd = this.getPageData();
        PageData res =new PageData();
        try {
            pd.put("IS_DEL",1);
            loanService.collateralinfo_del(pd);
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }


    /**
     * 查询人员信息
     */
    @RequestMapping(value = "/findByIdpersonnelInfo")
    @ResponseBody
    public PageData findByIdpersonnelInfo( ) {

        PageData pd = this.getPageData();
        PageData res =new PageData();
        try {

            PageData  data=   loanService.findByIdpersonnelInfo(pd);
            res.put("data", data);
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }

    /**
     * 删除个人信息
     */
    @RequestMapping(value = "/personnelInfo_del")
    @ResponseBody
    public Object personnelInfo_del( ) {

        PageData pd = this.getPageData();
        PageData res =new PageData();
        try {
            pd.put("IS_DEL",1);
            loanService.personnelInfo_del(pd);
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }


    /**
     * 查询人员情况
     */
    @RequestMapping(value = "/findByIdPersonnelSituation")
    @ResponseBody
    public PageData findByIdPersonnelSituation( ) {

        PageData pd = this.getPageData();
        PageData res =new PageData();
        try {

            PageData  data=   loanService.findByIdPersonnelSituation(pd);
            res.put("data", data);
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }

    /**
     * 删除个人情况
     */
    @RequestMapping(value = "/PersonnelSituation_del")
    @ResponseBody
    public Object PersonnelSituation_del( ) {

        PageData pd = this.getPageData();
        PageData res =new PageData();
        try {
            pd.put("IS_DEL",1);
            loanService.PersonnelSituation_del(pd);
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }

    /**
     * 查询银行信息
     */
    @RequestMapping(value = "/findByIdBank")
    @ResponseBody
    public PageData findByIdBank( ) {

        PageData pd = this.getPageData();
        PageData res =new PageData();
        try {

            PageData  data=   loanService.findByIdBank(pd);
            res.put("data", data);
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }


    /**
     * 删除银行信息
     */
    @RequestMapping(value = "/bank_del")
    @ResponseBody
    public Object bank_del( ) {

        PageData pd = this.getPageData();
        PageData res =new PageData();
        try {
            pd.put("IS_DEL",1);
            loanService.bank_del(pd);
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }






    /**
     * 删除股东信息
     */
    @RequestMapping(value = "/share_del")
    @ResponseBody
    public Object share_del( ) {

        PageData pd = this.getPageData();
        PageData res =new PageData();
        try {
            pd.put("IS_DEL",1);
            loanService.share_del(pd);
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }


    /**
     * 查询股东信息
     */
    @RequestMapping(value = "/findByIdShare")
    @ResponseBody
    public PageData findByIdShare( ) {

        PageData pd = this.getPageData();
        PageData res =new PageData();
        try {

            PageData  data=   loanService.findByIdShare(pd);
            res.put("data", data);
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }

    /**
     * 修改股东信息
     */
    @RequestMapping(value = "/share_update")
    @ResponseBody
    public Object share_update( ) {

        PageData pd = this.getPageData();
        PageData res =new PageData();
        try {

            loanService.share_update(pd);
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }




    /**
     * 新增--保存股东信息
     */
    @RequestMapping(value = "/saveShareholder")
    @ResponseBody
    public PageData saveShareholder() {
        DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition();
        defaultTransactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus status = transactionManager.getTransaction(defaultTransactionDefinition);

        logBefore(logger, "保存股东信息");
        PageData res = new PageData();
        PageData pd = this.getPageData();

        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);


        try {

            // 保存股东信息

            if(StringUtils.isBlank(pd.getString("ID"))){
                pd.put("ID", this.get32UUID()); //ID
                pd.put("IS_DEL", 0); //是否删除
                pd.put("CREATE_ID", user.getUSER_ID()); //创建用户
                pd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
                pd.put("UPDATE_ID", user.getUSER_ID()); //创建用户
                pd.put("UPDATE_DATE", new DateUtil().getTime());

                loanService.saveShareholder(pd);

            }else{
                pd.put("UPDATE_ID", user.getUSER_ID()); //创建用户
                pd.put("UPDATE_DATE", new DateUtil().getTime());
                loanService.editShareholder(pd);
            }


            //保存操作记录
            PageData oppd = new PageData();
            oppd.put("ID", this.get32UUID());    //主键
            oppd.put("IS_DEL", 0); //是否删除
            oppd.put("SORT", 0); //排序
            oppd.put("CREATE_ID", user.getUSER_ID()); //创建用户
            oppd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
            oppd.put("OPERA_TIME", new DateUtil().getTime()); //创建时间
            oppd.put("DETAILS", "创建合同，提交审核");//提交合同
           // oppd.put("CONTRACT_ID", contractId);
            oppd.put("OPERATOR", user.getNAME());
//            recordService.save(oppd);
            res.put("data", "");
            res.put("errcode", "0");
            res.put("errmsg", "ok");
            transactionManager.commit(status);
        } catch (Exception e) {
            transactionManager.rollback(status);
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }




    /**
     * 新增--保存银行账户
     */
    @RequestMapping(value = "/saveBankAccount")
    @ResponseBody
    public PageData saveBankAccount() {
        DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition();
        defaultTransactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus status = transactionManager.getTransaction(defaultTransactionDefinition);

        logBefore(logger, "保存股东信息");
        PageData res = new PageData();
        PageData pd = this.getPageData();

        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);


        try {

            // 保存银行信息

            if(StringUtils.isBlank(pd.getString("ID"))){
                pd.put("ID", this.get32UUID()); //ID
                pd.put("IS_DEL", 0); //是否删除
                pd.put("CREATE_ID", user.getUSER_ID()); //创建用户
                pd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
                pd.put("UPDATE_ID", user.getUSER_ID()); //创建用户
                pd.put("UPDATE_DATE", new DateUtil().getTime());

                loanService.saveBankAccount(pd);

            }else{
                pd.put("UPDATE_ID", user.getUSER_ID()); //创建用户
                pd.put("UPDATE_DATE", new DateUtil().getTime());
                loanService.editBankAccount(pd);
            }


            //保存操作记录
            PageData oppd = new PageData();
            oppd.put("ID", this.get32UUID());    //主键
            oppd.put("IS_DEL", 0); //是否删除
            oppd.put("SORT", 0); //排序
            oppd.put("CREATE_ID", user.getUSER_ID()); //创建用户
            oppd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
            oppd.put("OPERA_TIME", new DateUtil().getTime()); //创建时间
            oppd.put("DETAILS", "创建合同，提交审核");//提交合同
            // oppd.put("CONTRACT_ID", contractId);
            oppd.put("OPERATOR", user.getNAME());
//            recordService.save(oppd);
            res.put("data", "");
            res.put("errcode", "0");
            res.put("errmsg", "ok");
            transactionManager.commit(status);
        } catch (Exception e) {
            transactionManager.rollback(status);
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }




    //  人员情况
    /**
     * 新增--保存人员情况
     */
    @RequestMapping(value = "/savePersonnelSituation")
    @ResponseBody
    public PageData savePersonnelSituation() {
        DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition();
        defaultTransactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus status = transactionManager.getTransaction(defaultTransactionDefinition);

        logBefore(logger, "保存人员情况");
        PageData res = new PageData();
        PageData pd = this.getPageData();

        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);


        try {

            // 保存人员情况

            if(StringUtils.isBlank(pd.getString("ID"))){
                pd.put("ID", this.get32UUID()); //ID
                pd.put("IS_DEL", 0); //是否删除
                pd.put("CREATE_ID", user.getUSER_ID()); //创建用户
                pd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
                pd.put("UPDATE_ID", user.getUSER_ID()); //创建用户
                pd.put("UPDATE_DATE", new DateUtil().getTime());

                loanService.savePersonnelSituation(pd);

            }else{
                pd.put("UPDATE_ID", user.getUSER_ID()); //创建用户
                pd.put("UPDATE_DATE", new DateUtil().getTime());
                loanService.editPersonnelSituation(pd);
            }


            //保存操作记录
            PageData oppd = new PageData();
            oppd.put("ID", this.get32UUID());    //主键
            oppd.put("IS_DEL", 0); //是否删除
            oppd.put("SORT", 0); //排序
            oppd.put("CREATE_ID", user.getUSER_ID()); //创建用户
            oppd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
            oppd.put("OPERA_TIME", new DateUtil().getTime()); //创建时间
            oppd.put("DETAILS", "创建合同，提交审核");//提交合同
            // oppd.put("CONTRACT_ID", contractId);
            oppd.put("OPERATOR", user.getNAME());
//            recordService.save(oppd);
            res.put("data", "");
            res.put("errcode", "0");
            res.put("errmsg", "ok");
            transactionManager.commit(status);
        } catch (Exception e) {
            transactionManager.rollback(status);
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }





    //  人员信息
    /**
     * 新增--保存人员信息
     */
    @RequestMapping(value = "/savePersonnelInfo")
    @ResponseBody
    public PageData savePersonnelInfo() {
        DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition();
        defaultTransactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus status = transactionManager.getTransaction(defaultTransactionDefinition);

        logBefore(logger, "保存人员信息");
        PageData res = new PageData();
        PageData pd = this.getPageData();

        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);


        try {

            // 保存人员情况

            if(StringUtils.isBlank(pd.getString("ID"))){
                pd.put("ID", this.get32UUID()); //ID
                pd.put("IS_DEL", 0); //是否删除
                pd.put("CREATE_ID", user.getUSER_ID()); //创建用户
                pd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
                pd.put("UPDATE_ID", user.getUSER_ID()); //创建用户
                pd.put("UPDATE_DATE", new DateUtil().getTime());

                loanService.savePersonnelInfo(pd);

            }else{
                pd.put("UPDATE_ID", user.getUSER_ID()); //创建用户
                pd.put("UPDATE_DATE", new DateUtil().getTime());
                loanService.editPersonnelInfo(pd);
            }


            //保存操作记录
            PageData oppd = new PageData();
            oppd.put("ID", this.get32UUID());    //主键
            oppd.put("IS_DEL", 0); //是否删除
            oppd.put("SORT", 0); //排序
            oppd.put("CREATE_ID", user.getUSER_ID()); //创建用户
            oppd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
            oppd.put("OPERA_TIME", new DateUtil().getTime()); //创建时间
            oppd.put("DETAILS", "创建合同，提交审核");//提交合同
            // oppd.put("CONTRACT_ID", contractId);
            oppd.put("OPERATOR", user.getNAME());
//            recordService.save(oppd);
            res.put("data", "");
            res.put("errcode", "0");
            res.put("errmsg", "ok");
            transactionManager.commit(status);
        } catch (Exception e) {
            transactionManager.rollback(status);
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }



    /**
     * 新增--保存不动产
     */
    @RequestMapping(value = "/saveRealEstateInfo")
    @ResponseBody
    public PageData saveRealEstateInfo() {
        DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition();
        defaultTransactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus status = transactionManager.getTransaction(defaultTransactionDefinition);

        logBefore(logger, "保存不动产");
        PageData res = new PageData();
        PageData pd = this.getPageData();

        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);


        try {

            // 保存人员情况

            if(StringUtils.isBlank(pd.getString("ID"))){
                pd.put("ID", this.get32UUID()); //ID
                pd.put("IS_DEL", 0); //是否删除
                pd.put("CREATE_ID", user.getUSER_ID()); //创建用户
                pd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
                pd.put("UPDATE_ID", user.getUSER_ID()); //创建用户
                pd.put("UPDATE_DATE", new DateUtil().getTime());

                loanService.saveRealEstateInfo(pd);

            }else{
                pd.put("UPDATE_ID", user.getUSER_ID()); //创建用户
                pd.put("UPDATE_DATE", new DateUtil().getTime());
                loanService.editRealEstateInfo(pd);
            }


            //保存操作记录
            PageData oppd = new PageData();
            oppd.put("ID", this.get32UUID());    //主键
            oppd.put("IS_DEL", 0); //是否删除
            oppd.put("SORT", 0); //排序
            oppd.put("CREATE_ID", user.getUSER_ID()); //创建用户
            oppd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
            oppd.put("OPERA_TIME", new DateUtil().getTime()); //创建时间
            oppd.put("DETAILS", "创建合同，提交审核");//提交合同
            // oppd.put("CONTRACT_ID", contractId);
            oppd.put("OPERATOR", user.getNAME());
//            recordService.save(oppd);
            res.put("data", "");
            res.put("errcode", "0");
            res.put("errmsg", "ok");
            transactionManager.commit(status);
        } catch (Exception e) {
            transactionManager.rollback(status);
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }


    /**
     * 新增--保存动产
     */
    @RequestMapping(value = "/saveMovableInfo")
    @ResponseBody
    public PageData saveMovableInfo() {
        DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition();
        defaultTransactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus status = transactionManager.getTransaction(defaultTransactionDefinition);

        logBefore(logger, "保存动产");
        PageData res = new PageData();
        PageData pd = this.getPageData();

        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);


        try {



            if(StringUtils.isBlank(pd.getString("ID"))){
                pd.put("ID", this.get32UUID()); //ID
                pd.put("IS_DEL", 0); //是否删除
                pd.put("CREATE_ID", user.getUSER_ID()); //创建用户
                pd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
                pd.put("UPDATE_ID", user.getUSER_ID()); //创建用户
                pd.put("UPDATE_DATE", new DateUtil().getTime());

                loanService.saveMovableInfo(pd);

            }else{
                pd.put("UPDATE_ID", user.getUSER_ID()); //创建用户
                pd.put("UPDATE_DATE", new DateUtil().getTime());
                loanService.editMovableInfo(pd);
            }


            //保存操作记录
            PageData oppd = new PageData();
            oppd.put("ID", this.get32UUID());    //主键
            oppd.put("IS_DEL", 0); //是否删除
            oppd.put("SORT", 0); //排序
            oppd.put("CREATE_ID", user.getUSER_ID()); //创建用户
            oppd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
            oppd.put("OPERA_TIME", new DateUtil().getTime()); //创建时间
            oppd.put("DETAILS", "创建合同，提交审核");//提交合同
            // oppd.put("CONTRACT_ID", contractId);
            oppd.put("OPERATOR", user.getNAME());
//            recordService.save(oppd);
            res.put("data", "");
            res.put("errcode", "0");
            res.put("errmsg", "ok");
            transactionManager.commit(status);
        } catch (Exception e) {
            transactionManager.rollback(status);
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }



    /**
     * 新增--保存抵押物信息
     */
    @RequestMapping(value = "/saveCllateralInfo")
    @ResponseBody
    public PageData saveCllateralInfo() {
        DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition();
        defaultTransactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus status = transactionManager.getTransaction(defaultTransactionDefinition);

        logBefore(logger, "保存抵押物信息");
        PageData res = new PageData();
        PageData pd = this.getPageData();

        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);


        try {



            if(StringUtils.isBlank(pd.getString("ID"))){
                pd.put("ID", this.get32UUID()); //ID
                pd.put("IS_DEL", 0); //是否删除
                pd.put("CREATE_ID", user.getUSER_ID()); //创建用户
                pd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
                pd.put("UPDATE_ID", user.getUSER_ID()); //创建用户
                pd.put("UPDATE_DATE", new DateUtil().getTime());

                loanService.saveCllateralInfo(pd);

            }else{
                pd.put("UPDATE_ID", user.getUSER_ID()); //创建用户
                pd.put("UPDATE_DATE", new DateUtil().getTime());
                loanService.editCllateralInfo(pd);
            }


            //保存操作记录
            PageData oppd = new PageData();
            oppd.put("ID", this.get32UUID());    //主键
            oppd.put("IS_DEL", 0); //是否删除
            oppd.put("SORT", 0); //排序
            oppd.put("CREATE_ID", user.getUSER_ID()); //创建用户
            oppd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
            oppd.put("OPERA_TIME", new DateUtil().getTime()); //创建时间
            oppd.put("DETAILS", "创建合同，提交审核");//提交合同
            // oppd.put("CONTRACT_ID", contractId);
            oppd.put("OPERATOR", user.getNAME());
//            recordService.save(oppd);
            res.put("data", "");
            res.put("errcode", "0");
            res.put("errmsg", "ok");
            transactionManager.commit(status);
        } catch (Exception e) {
            transactionManager.rollback(status);
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }


    /**
     * 新增--保存抵押物动产信息
     */
    @RequestMapping(value = "/saveMovableCollateralInfo")
    @ResponseBody
    public PageData saveMovableCollateralInfo() {
        DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition();
        defaultTransactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus status = transactionManager.getTransaction(defaultTransactionDefinition);

        logBefore(logger, "保存抵押物动产信息");
        PageData res = new PageData();
        PageData pd = this.getPageData();

        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);


        try {



            if(StringUtils.isBlank(pd.getString("ID"))){
                pd.put("ID", this.get32UUID()); //ID
                pd.put("IS_DEL", 0); //是否删除
                pd.put("CREATE_ID", user.getUSER_ID()); //创建用户
                pd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
                pd.put("UPDATE_ID", user.getUSER_ID()); //创建用户
                pd.put("UPDATE_DATE", new DateUtil().getTime());

                loanService.saveMovableCollateralInfo(pd);

            }else{
                pd.put("UPDATE_ID", user.getUSER_ID()); //创建用户
                pd.put("UPDATE_DATE", new DateUtil().getTime());
                loanService.editMovableCollateralInfo(pd);
            }


            //保存操作记录
            PageData oppd = new PageData();
            oppd.put("ID", this.get32UUID());    //主键
            oppd.put("IS_DEL", 0); //是否删除
            oppd.put("SORT", 0); //排序
            oppd.put("CREATE_ID", user.getUSER_ID()); //创建用户
            oppd.put("CREATE_DATE", new DateUtil().getTime()); //创建时间
            oppd.put("OPERA_TIME", new DateUtil().getTime()); //创建时间
            oppd.put("DETAILS", "创建合同，提交审核");//提交合同
            // oppd.put("CONTRACT_ID", contractId);
            oppd.put("OPERATOR", user.getNAME());
//            recordService.save(oppd);
            res.put("data", "");
            res.put("errcode", "0");
            res.put("errmsg", "ok");
            transactionManager.commit(status);
        } catch (Exception e) {
            transactionManager.rollback(status);
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }

}
